#pragma once

#include <iostream>
#include <fstream>
#include <string>
#include <boost/algorithm/string.hpp>
#include "inc/cppjieba/Jieba.hpp"

namespace ns_util
{
    class Util
    {
    public:
        // 文件读取函数
        static bool ReadFile(const std::string& file, std::string* fileContent)
        {
            std::ifstream in(file.c_str(), std::ios_base::in);

            // 判断文件是否打开成功
            if(!in.is_open())
            {
                std::cerr << "file. " << file << "open error" << std::endl;
                return false;
            }

            // 逐行读取文件内容
            std::string line;
            while(std::getline(in, line))
            {
                (*fileContent) += line; 
            }

            in.close();

            return true;
        }
    };

    // 字符串处理工具类
    class StringUtil
    {
    public:
        static void Split(std::vector<std::string>* out, const std::string& target, const std::string& sep)
        {
            boost::split(*out, target, boost::is_any_of(sep), boost::token_compress_on);
        } 
    };

    // 词库路径
    const char* const DICT_PATH = "./dict/jieba.dict.utf8";
    const char* const HMM_PATH = "./dict/hmm_model.utf8";
    const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char* const IDF_PATH = "./dict/idf.utf8";
    const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";

    // jieba分词处理工具类
    class JiebaUtil
    {
    private:
        static cppjieba::Jieba jieba;
    
    public:
        // jieba分词函数
        static void CutString(const std::string& s, std::vector<std::string>* cutResults)
        {
            JiebaUtil::jieba.CutForSearch(s, *cutResults);
        }
    };

    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);
} 
